/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view;

import javax.swing.table.AbstractTableModel;
import model.Person;
import model.User;

/**
 *
 * @author Ira
 */
public class TableUser extends AbstractTableModel  {

	private String[] headers = {"Nom", "Prénom", "Pseudo", "Type", "Docs empruntés", "Docs réservés", "Docs en retard"};
	private Person[] users;
	
	public TableUser(Person[] users) {
		this.users = users;
	}
	
	@Override
	public int getRowCount() {
		return this.users == null ? 0: this.users.length;
	}

	@Override
	public int getColumnCount() {
		return this.headers.length;
	}
	
	@Override
	public String getColumnName(int columnIndex) {
		return this.headers[columnIndex];
    }

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		boolean isUser = !this.users[rowIndex].getType().equals("Bibliothécaire");
		switch(columnIndex) {
			case 0:
				return this.users[rowIndex].getName();
			case 1:
				return this.users[rowIndex].getFirstName();
			case 2:
				return this.users[rowIndex].getPseudo();
			case 3:
				return this.users[rowIndex].getType();
			case 4:
				return isUser ? "" + ((User)this.users[rowIndex]).getNBBorrow(): "";
			case 5:
				return isUser ? "" + ((User)this.users[rowIndex]).getNBReserve(): "";
			case 6:
				return isUser ? "" + ((User)this.users[rowIndex]).getNBLate(): "";
			default:
				return null;
		}
	}
	
	@Override
	public Class getColumnClass(int columnIndex){
		switch(columnIndex){
			default:
				return Object.class;
		}
	}
}
